package com.axc.gallery2.net;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo.State;
import android.provider.Settings;

import com.axc.gallery2.R;

public class CheckNetworkState extends Activity{
    
    private Context context;
    public CheckNetworkState(Context context) {
        this.context = context;
    }
    /**
     * 网络连接状态 判断是否连接网络，返回值如下 -1表示网络 0表示2G或3G网络连接 1表示wifi连接
     **/
    public int NetworkState() {
        String service = Context.CONNECTIVITY_SERVICE;
        ConnectivityManager manager = (ConnectivityManager)context.getSystemService(service);       
        State mobileState = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
        State wifiState = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
        if (mobileState == State.CONNECTED || mobileState == State.CONNECTING)
            return 0;
        if (wifiState == State.CONNECTED || wifiState == State.CONNECTING)
            return 1;
        else
            return -1;
    }

    /** 
     * 设置网络提醒
     **/
    public void setNetworkTips() {
        System.out.println("// 进入网络设置界面111");
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setIcon(android.R.drawable.ic_dialog_alert);
        builder.setTitle(R.string.netstate);
        builder.setMessage(R.string.setnetwork);
        System.out.println("// 进入网络设置界面222");
        builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override
            public void onClick(DialogInterface dialog, int which) {
                                // 进入网络设置界面
                System.out.println("// 进入网络设置界面");
                context.startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
                System.out.println("haha");
                }
                        });
        builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
                }
                        });
        builder.create();
        builder.show();
    }

}
